package org.ztr.yanai.ai.controller.chat;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: ZhaoTR
 * @Date: Created in 2025/10/30 20:20
 * @Description: 测试ChatModel
 * @Version: 1.0
 */

@RestController
@RequestMapping("/ai")
public class ChatModelController {
    @Resource //支持自动注入
    private ChatModel dashscopeChatModel;

    /*@Resource //ChatClient 不支持自动注入
    private ChatClient chatClient;*/

    /**
     * http://localhost:8003/chatmodel/dochat
     * @param msg 输入
     * @return 输出
     */
    @GetMapping("/chatmodel/dochat")
    public String doChat(@RequestParam(name = "msg", defaultValue = "你是谁") String msg) {
        String result = dashscopeChatModel.call(msg);
        System.out.println("响应：" + result);
        return result;
    }
}
